package test_model_base;

import java.sql.Date;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.servlet.model.base.News;

public class NewsTest extends TestCase {
	private News news;
	private Date date_publish;
	@Before
	public void setUp() throws Exception {
		super.setUp();
		news = new News();
		date_publish = Date.valueOf("2012-01-26");
	}

	@After
	public void tearDown() throws Exception {
		super.tearDown();
		news = null;
		date_publish = null;
	}

	@Test
	public void testNews() {
		Assert.assertNotNull(news);
		Assert.assertNull(news.getEmail_user1());
		Assert.assertNull(news.getEmail_user2());
	}

	@Test
	public void testNewsStringStringDate() {
		news = new News("jialin.liu@u-psud.fr", "jingjing.li@u-psud.fr", date_publish,0);
		Assert.assertNotNull(news);
		Assert.assertEquals("jialin.liu@u-psud.fr", news.getEmail_user1());
		Assert.assertEquals("jingjing.li@u-psud.fr", news.getEmail_user2());
	}

	@Test
	public void testGetEmail_user1() {
		Assert.assertNull( news.getEmail_user1() );
		news.setEmail_user1("jialin.liu@u-psud.fr");
		Assert.assertEquals("jialin.liu@u-psud.fr", news.getEmail_user1());
	}

	@Test
	public void testGetEmail_user2() {
		Assert.assertNull( news.getEmail_user2() );
		news.setEmail_user2("jingjing.li@u-psud.fr");
		Assert.assertEquals("jingjing.li@u-psud.fr", news.getEmail_user2());
	}

	@Test
	public void testSetEmail_user1() {		
		Assert.assertNull( news.getEmail_user1() );
		news.setEmail_user1("jialin.liu@u-psud.fr");
		Assert.assertEquals("jialin.liu@u-psud.fr", news.getEmail_user1());
	}

	@Test
	public void testSetEmail_user2() {
		Assert.assertNull( news.getEmail_user2() );
		news.setEmail_user2("jingjing.li@u-psud.fr");
		Assert.assertEquals("jingjing.li@u-psud.fr", news.getEmail_user2());
	}


	@Test
	public void testGenerateInsertSQL() {
		Assert.assertEquals("INSERT INTO news VALUES ('null' ,'null' , null, 0 , null)", news.generateInsertSQL());
		news = new News("jialin.liu@u-psud.fr", "jingjing.li@u-psud.fr", null,0);
		Assert.assertEquals("INSERT INTO news VALUES ('jialin.liu@u-psud.fr' ,'jingjing.li@u-psud.fr' , null, 0 , null)", news.generateInsertSQL());
		news = new News("jialin.liu@u-psud.fr", "jingjing.li@u-psud.fr", date_publish,0);
		Assert.assertEquals("INSERT INTO news VALUES ('jialin.liu@u-psud.fr' ,'jingjing.li@u-psud.fr' ,'2012-01-26', 0 , null)", news.generateInsertSQL());
	}

	@Test
	public void testGenerateDeleteSQL() {
		Assert.assertEquals("DELETE FROM news WHERE id='0'", news.generateDeleteSQL());
		news = new News("jialin.liu@u-psud.fr", "jingjing.li@u-psud.fr", null,0);
		Assert.assertEquals("DELETE FROM news WHERE id='0'", news.generateDeleteSQL());
	}

}
